package com.huadao.cart_ccs.experiment.log.deviceLog;

import android.content.Context;
import android.os.Bundle;

import com.huadao.cart_ccs.R;
import com.huadao.cart_ccs.common.TimeUtil;
import com.huadao.cart_ccs.common.adapter.CommonRecycleAdapter;
import com.huadao.cart_ccs.common.adapter.CommonViewHolder;
import com.huadao.cart_ccs.common.adapter.FooterHolder;
import com.huadao.cart_ccs.common.adapter.HeaderHolder;
import com.huadao.cart_ccs.common.adapter.onItemCommonClickListener;
import com.huadao.cart_ccs.experiment.log.baseLoglist.BaseLogListFrag;
import com.huadao.cart_ccs.experiment.log.baseLoglist.BaseLogListPresenter;
import com.huadao.cart_ccs.greendao.entity.DeviceRecord;
import com.huadao.cart_ccs.greendao.entity.Operation;

import java.util.List;

public class DeviceRecordFrag extends BaseLogListFrag {

    public static DeviceRecordFrag getInstance(int day,String condition){
        Bundle bundle=new Bundle();
        bundle.putInt("day",day);
        bundle.putString("condition",condition);
        DeviceRecordFrag deviceRecordFrag=new DeviceRecordFrag();
        deviceRecordFrag.setArguments(bundle);
        return deviceRecordFrag;
    }

    @Override
    protected BaseLogListPresenter createPresenter() {
        return new DeviceRecordPresenter(this);
    }

    @Override
    protected CommonRecycleAdapter setAdapter() {
        return new DeviceRecordAdapter(getActivity(),dataList,R.layout.item_device_record,R.layout.head_device_record,R.layout.rv_footer);
    }

    class DeviceRecordAdapter extends CommonRecycleAdapter<DeviceRecord>{

        public DeviceRecordAdapter(Context context, List<DeviceRecord> dataList, int layoutId, int headerLayoutId, int footerLayoutId) {
            super(context, dataList, layoutId, headerLayoutId, footerLayoutId);
        }

        private onItemCommonClickListener commonClickListener = new onItemCommonClickListener() {
            @Override
            public void onItemClickListener(int position) {
                if (position == dataList.size()+1) {
                    loadMoreData();
                } else {
                }
            }

            @Override
            public void onItemLongClickListener(int position) {

            }
        };

        @Override
        protected void bindData(CommonViewHolder holder, DeviceRecord data) {
            holder.setText(R.id.tv_time,TimeUtil.log_sdf.format(data.getDateTime()));
            holder.setText(R.id.tv_operator,data.getOperator());
            holder.setText(R.id.tv_operate,data.getName());
            holder.setText(R.id.tv_data,data.getData());
            holder.setText(R.id.tv_direction,data.getDirection());
        }

        @Override
        protected void bindFooterData(FooterHolder holder) {
            holder.setCommonClickListener(commonClickListener);
        }

        @Override
        protected void bindHeaderData(HeaderHolder holder) {
            holder.setText(R.id.tv_time,"时间");
            holder.setText(R.id.tv_operator,"操作人");
            holder.setText(R.id.tv_operate,"类型");
            holder.setText(R.id.tv_data,"数值");
            holder.setText(R.id.tv_direction,"方向");
        }
    }
}
